package com.googlecode.recycled.drools;

import com.google.common.collect.ImmutableMap;
import com.googlecode.recycled.lang.assertions.Assert;
import org.drools.runtime.rule.RuleContext;

import javax.annotation.Nullable;
import java.util.Map;

/**
 * @author Henryk Konsek
 */
public class MapUseCaseExecutor implements UseCaseExecutor {

    protected Map<String, UseCase> consequences;

    public MapUseCaseExecutor(Map<String, UseCase> consequences) {
        this.consequences = ImmutableMap.copyOf(Assert.notEmpty(consequences));
    }

    @Override
    public void fire(RuleContext ruleContext, @Nullable Object fact) {
        String ruleName = Assert.notNull(ruleContext).getRule().getName();
        Assert.notNull(consequences.get(ruleName), ruleName).fire(ruleContext, fact);
    }

}
